<?php
    class Category extends MY_Controller {

        function _init() {
            $this->resource = 'category';
            $this->load->model('page_model', 'pages');
            $this->load->model('catalog_category', 'categories');
            $this->load->model('catalog_stuff', 'stuff');
        }

        function index() {

        }

        function view($id = 0) {
            $page = $this->pages->getPage($id);

            $sub_result = $this->categories->getChildCategories($id);
            if($sub_result == FALSE) {
                $cats = array();
            } else {
                $cats = $sub_result;
            }

            $sub_result = $this->stuff->getStuffByCategoryId($id);
            if($sub_result == FALSE) {
                $stuff = array();
            } else {
                $stuff = $sub_result;
            }

            $view_data = array(
                'VIEW' => 'category',
                'PAGE' => $page,
                'CATEGORIES' => $cats,
                'STUFF' => $stuff,
            );
            $this->load->vars($view_data);
            $this->layout->load('category');
        }
        
        function detail($id) {
            $item = $this->stuff->getStuffItem($id);            
            
            
            $view_data = array(
                'VIEW' => 'detail',
                'ITEM' => $item,               
            );
            $this->load->vars($view_data);
            $this->layout->load('detail');
        }

    }
?>